package com.example.redisdemo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.redisdemo.entity.Record;
import com.example.redisdemo.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ProjectName: redisdemo
 * @Package: com.example.redisdemo.controller
 * @ClassName: RecordController
 * @Author: zlx
 * @Description:
 * @Date: 2022/6/18 0:35
 * @Version: 1.0
 */
@RestController
@RequestMapping("/record")
public class RecordController {
    @Autowired
    private RecordService recordService;

    /**
     * 新增记录
     * zlx
     * 10:04 2022/6/18
     * @param record 记录内容
     * @return com.example.redisdemo.entity.Record
     **/
    @PostMapping
    public Record addRecord(@RequestBody Record record) {
        return recordService.addRecord(record);
    }

    /**
     * 根据id删除记录
     * zlx
     * 10:09 2022/6/18
     * @param recordId 记录id
     * @return java.lang.String
     **/
    @DeleteMapping("/{recordId}")
    public String delRecord(@PathVariable String recordId) {
        return recordService.delRecord(recordId) ? "删除成功" : "删除失败";
    }

    /**
     * 修改记录内容
     * zlx
     * 10:06 2022/6/18
     * @param record
     * @return com.example.redisdemo.entity.Record
     **/
    @PutMapping
    public Record putRecord(@RequestBody Record record) {
        return recordService.putRecord(record);
    }

    /**
     * 分页获取记录列表
     * zlx
     * 10:11 2022/6/18
     * @param page      分页信息
     * @param record    记录查询信息
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.example.redisdemo.entity.Record>
     **/
    @GetMapping
    public IPage<Record> getRecordPage(Page page,Record record) {
        return recordService.getRecordPage(page,record);
    }

    /**
     * 根据记录id获取记录详情
     * zlx
     * 10:12 2022/6/18
     * @param recordId  记录id
     * @return com.example.redisdemo.entity.Record
     **/
    @GetMapping("/{recordId}")
    public Record getRecordById(@PathVariable String recordId) {
        return recordService.getRecordById(recordId);
    }
}
